﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.UI
{
    public class DataFilter : IEnumerable
    {
        protected List<string> filters = new List<string>();

        public void Add(string itemID)
        {
            filters.Add(itemID);
        }

        public void Clear()
        {
            filters.Clear();
        }

        public IEnumerator<string> GetEnumerator()
        {
            foreach (var item in filters)
            {
                yield return item;
            }
        }

        public bool Contains(string seriesId)
        {
            if (filters.Contains(seriesId))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        public int Count
        {
            get
            {
                return filters.Count;
            }
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            foreach(var item in filters)
            {
                sb.Append(item);
                sb.Append(",");
            }

            return sb.ToString().TrimEnd(',');
        }

        public void InitByText(string text)
        {
            filters.Clear();
            if (!string.IsNullOrWhiteSpace(text))
            {
                string[] filterArray = text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var item in filterArray)
                {
                    filters.Add(item);
                }
            }
        }
    }
}
